package net.caixiaomi.info.life;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;

import net.caixiaomi.info.R;
import net.caixiaomi.info.util.FileHelper;
import net.caixiaomi.info.util.ToastUtil;

/**
 * Created by mac on 2018/11/1.
 */

public class EWMDialog extends BaseDialog implements View.OnClickListener{

    private String mContent;
    private RelativeLayout saveLocalRl;
    private ImageView mImgIv;
    private Context mContext;

    public EWMDialog(@NonNull Context context) {
        super(context);
        mContext=context;
    }

    public void setImgUrl(String url){
        mContent=url;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.erweima_layout);
        mImgIv=findViewById(R.id.ewm_iv);
        Glide.with(mContext).load(mContent).into(mImgIv);
        findViewById(R.id.save_local_rl).setOnClickListener(this);
        setCanceledOnTouchOutside(true);
        setGravity(Gravity.CENTER,23,0);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.save_local_rl:
                Bitmap b = Bitmap.createBitmap(mImgIv.getMeasuredWidth(), mImgIv.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(b);
                c.drawColor(Color.WHITE);
                mImgIv.draw(c);
                FileHelper.saveBitmap(mContext,b,"erweima");
                ToastUtil.s("保存成功");
                break;
        }
    }
}
